package com.vip.mongofile.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;

/**
 * @Description: 文件存储枚举
 * @Date: 2020/12/07 09:56
 * @Author: wp
 **/
@Getter
@RequiredArgsConstructor
public enum FileStorageEnum {

    /**
     * mongo小文件策略
     */
    MONGO("mongo","小文件上传","com.vip.mongofile.service.impl.MongoFileStorageServiceImpl",true),
    /**
     *  mongo大文件策略
     */
    MONGO_BIG("mongo_big","大文件上传","com.vip.mongofile.service.impl.BigFileStorageServiceImpl",true),
    /**
     * min_io对象存储策略
     */
    MIN_IO("min_io","文件上传","to do implement",false),
    /**
     * 其他策略
     */
    OTHER("other","文件上传","to do implement",false);

    private final String type;
    private final String desc;
    private final String clazz;
    private final boolean support;

    public static FileStorageEnum getFileStorageEnum(String type) {
        return Arrays.stream(FileStorageEnum.values())
                .filter(e -> e.getType().equals(type) && e.support).findFirst()
                .orElseThrow(() -> new IllegalArgumentException(String.format(" storage strategy can not support %s ", type)));
    }

}
